const EXCELJS = require('exceljs');
const fs = require('fs')
const WORKBOOK = new EXCELJS.Workbook();

// 注册角色
const Role = {
    '商户': 1,
    '购买方': 2,
    '技术经理人': 3
}

async function readExcel(filePath) {
    await WORKBOOK.xlsx.readFile(filePath);
    const SHEET = WORKBOOK.worksheets[0];
    let arr = []
    SHEET.eachRow((row, rowNumber) => {
        let obj = {
            "id": new Date().getTime() + rowNumber,
            "company": row.getCell(1).text,
            "phone": row.getCell(2).text,
            "role": Role[row.getCell(3).text],
            "password": "XZ123456"
        }
        arr.push(obj)
    });
    let p = {
        author: arr
    }
    fs.writeFile('author.json', JSON.stringify(p), () => {
        console.log('write');
    })
}

readExcel('./author.xlsx');